package edu.pku.sei.modeler.uml.commands.usecase;

import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.model.uml.UseCases.UseCase;
import edu.pku.sei.modeler.uml.commands.NestedElementCreateCommand;

public class NestedUseCaseCreateCommand extends NestedElementCreateCommand {

	public NestedUseCaseCreateCommand(MetaNode node, MetaNode hostNode,
			Rectangle constraint) {
		super(node, hostNode, constraint);
	}

	@Override
	public boolean canExecute() {
		return super.canExecute()
				&& fatherNode.getModelElement() instanceof Classifier
				&& node.getModelElement() instanceof UseCase;
	}

	@Override
	protected void updateModelElement() {
		MetaModelElement modelElement = this.node.getModelElement();
		Classifier classifier = (Classifier) fatherNode.getModelElement();
		classifier.getOwnedUseCase().add(modelElement);
	}

	@Override
	protected void undoModelElement() {
		Classifier classifier = (Classifier) fatherNode.getModelElement();
		classifier.getOwnedUseCase().remove(node.getModelElement());
	}

}
